#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from cStringIO import StringIO
from random import Random

from django.db import models
from django.contrib.auth.models import User 
from django.core.files.uploadedfile import SimpleUploadedFile
from django.conf import settings

class UserProfile(models.Model):
    """
    This model is an extension of django.contrib.auth.models.User using the
    Django UserProfile mechanism as documented here :
    http://docs.djangoproject.com/en/1.2/topics/auth/#storing-additional-information-about-users
    If you want to use it, get a User object eg. request.user and call the
    get_profile() method eg. user.get_profile()

    Anything about django.contrib.auth.models.User can be found here :
    http://docs.djangoproject.com/en/1.2/topics/auth/#users

    Alternatively check the Howto in the wiki :
    http://ewoche.polythematik.de/projects/ewochenwebsite/wiki/Usermanagement_Howto
    """
    user = models.OneToOneField(User)
    activation_hash = models.CharField(max_length = 40, blank=True) # Random 40 char hash
    accepted_terms = models.BooleanField(default = False) # flag if the newest terms were accepted by this user

    def __unicode__(self):
        return self.user.username

    @classmethod
    def generate_activation_hash(cls):
        random_number_generator = Random()
        
        allchars = '789yuiophjknmYUIPHJKLNM23456qwertasdfgzxcvbQWERTASDFGZXCVB'
        key = ''
        for i in range(40):
            key = key + random_number_generator.choice(allchars)

        return key
